package net.sk.china.city.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import net.sk.china.city.controller.base.BaseController;
import net.sk.china.city.domain.dto.AjaxResult;
import net.sk.china.city.domain.ArHomeSupplier;
import net.sk.china.city.service.IArHomeSupplierService;
import net.sk.china.city.domain.dto.TableDataInfo;

/**
 * 供应商列表Controller
 * 
 * @author gxf
 * @date 2024-05-08
 */
@Api(tags = "供应商")
@RequiredArgsConstructor
@RestController
@RequestMapping("/yigoHome/supplier")
public class ArHomeSupplierController extends BaseController
{
    @Autowired
    private IArHomeSupplierService arHomeSupplierService;

    /**
     * 查询供应商列表列表
     */
    @ApiOperation("供应商列表")
    @PreAuthorize("hasAnyAuthority('yigoHome:supplier:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArHomeSupplier arHomeSupplier)
    {
        startPage();
        List<ArHomeSupplier> list = arHomeSupplierService.selectArHomeSupplierList(arHomeSupplier);
        return getDataTable(list);
    }

    /**
     * 导出供应商列表列表
     */
    @PreAuthorize("hasAnyAuthority('yigoHome:supplier:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArHomeSupplier arHomeSupplier)
    {
        List<ArHomeSupplier> list = arHomeSupplierService.selectArHomeSupplierList(arHomeSupplier);
//        ExcelUtil<ArHomeSupplier> util = new ExcelUtil<ArHomeSupplier>(ArHomeSupplier.class);
//        util.exportExcel(response, list, "供应商列表数据");
    }

    /**
     * 获取供应商列表详细信息
     */
    @ApiOperation("供应商详情")
    @PreAuthorize("hasAnyAuthority('yigoHome:supplier:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(arHomeSupplierService.selectArHomeSupplierById(id));
    }

    /**
     * 新增供应商列表
     */
    @ApiOperation("新增供应商")
    @PreAuthorize("hasAnyAuthority('yigoHome:supplier:add')")
    @PostMapping
    public AjaxResult add(@RequestBody ArHomeSupplier arHomeSupplier)
    {
        return toAjax(arHomeSupplierService.insertArHomeSupplier(arHomeSupplier));
    }

    /**
     * 修改供应商列表
     */
    @ApiOperation("修改供应商")
    @PreAuthorize("hasAnyAuthority('yigoHome:supplier:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody ArHomeSupplier arHomeSupplier)
    {
        return toAjax(arHomeSupplierService.updateArHomeSupplier(arHomeSupplier));
    }

    /**
     * 删除供应商列表
     */
    @ApiOperation("删除供应商")
    @PreAuthorize("hasAnyAuthority('yigoHome:supplier:remove')")
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long[] id)
    {
        return toAjax(arHomeSupplierService.deleteArHomeSupplierByIds(id));
    }

    @ApiOperation("查询所有供应商")
    @GetMapping(value = "/getSuppliers")
    public AjaxResult getSuppliers()
    {
        return success(arHomeSupplierService.getSuppliers());
    }
}
